package com.violet.advice;

import com.violet.domain.exceptions.DTOVerifyException;
import com.violet.domain.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(DTOVerifyException.class)
    public Result<String> handleException(DTOVerifyException e) {
        log.warn(e.getMessage());
        return Result.error(e.show);
    }

    @ExceptionHandler(RuntimeException.class)
    public Result<String> handleException(RuntimeException e) {
        log.error(e.getMessage());
        return Result.error("服务器错误");
    }

    @ExceptionHandler(Exception.class)
    public Result<String> handleException(Exception e) {
        return Result.error("服务器内部错误: " + e.getMessage());
    }
}
